package com.lhoverc.mapper;

import com.lhoverc.pojo.VO.UserInfoVO;
import com.lhoverc.pojo.dto.LoginUserDto;
import com.lhoverc.pojo.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-04-12
 * @Description:
 * @Version: 1.0
 */
@Mapper
public interface UserMapper {
    /**
     * 根据用户名和密码查询用户信息
     *
     * @param loginUserDto
     * @return
     */
    @Select("select * from user where phone = #{phone} and password = #{password} and is_delete = 0")
    UserEntity getByPhoneAndPassword(LoginUserDto loginUserDto);

    /**
     * 修改用户是否删除的属性(通过设置该属性代替删除)
     *
     * @param id
     */
    @Update("update user set is_delete = 1 where id = #{id}")
    void updateIsDelete(Integer id);

    /**
     * 新增用户
     *
     * @param user
     */
    void insertUser(UserEntity user);

    /**
     * 修改用户信息
     *
     * @param user
     */
    void updateUser(UserEntity user);

    /**
     * 条件查询
     *
     * @param username
     * @param address
     * @param status
     * @return
     */
    List<UserEntity> page(String username, String address, Integer status);

    /**
     * 通过id查询用户姓名
     *
     * @param userId
     * @return
     */
    @Select("select username from user where id = #{userId}")
    String getUsernameById(Integer userId);

    /**
     * 修改账户密码
     *
     * @param email
     * @param password
     */
    @Update("update user set password = #{password} where email = #{email} and is_delete = 0")
    void updatePassword(String email, String password);

    /**
     * 查询id通过姓名
     *
     * @param operatorName
     * @return
     */
    @Select("select id from user where username like concat('%', #{username}, '%')")
    List<Integer> getIdByUsername(String operatorName);

    /**
     * 获取user数据通过id
     *
     * @param id
     * @return
     */
    @Select("select * from user u, user_affiliation ua where u.id = ua.user_id and u.id = #{id} and u.is_delete = 0")
    UserInfoVO getUserById(Integer id);

    /**
     * 查询用户总数
     * @return
     */
    @Select("select count(*) from user where is_delete = 0")
    Integer getUserNum();
}
